<template>
	<view>
		<view class="result">
			<image class="bg" src="../../../static/2images/result_error.png" mode=""></image>
			<view class="head" v-if="type == 'error'">
				<image class="icon" src="../../../static/2images/icon_error.png"></image>
				<text >预订失败！</text>
			</view>
			<view class="" v-else>
				<image class="icon" src="../../../static/2images/icon_error.png"></image>
				<text >预订成功！</text>
			</view>
			<view class="" v-if="type == 'error'">
				<view class="err-text">支付失败</view>
				<view class="btn1 btn3" @click="onPay">重新支付</view>
			</view>
			<view class="" v-else>
				<view class="name">北京烤鸭（冉家坝店）</view>
				<view class="desc">您可以在线马上点餐，以便我们为您提前准备 餐食</view>
				<view class="info">
					<view class="info-item">
						<view class="text1">包房</view>
						<view class="text2">用餐人数</view>
						<view class="text3">10人</view>
					</view>
					<view class="info-item">
						<view class="text1"></view>
						<view class="text2">预订到店时间</view>
						<view class="text3">今日 14:30</view>
					</view>
				</view>
				<view class="btn1" @click="goHome">在线点菜</view>
				<view class="btn2">不点菜，返回首页</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: '',
				orderId:''
			};
		},
		onLoad(options) {
			this.type = options.type
			this.orderId = options.orderId
			console.log(this.orderId);
		},
		methods: {
			onPay(){
				
				let config= JSON.parse(this.config)
				console.log(config);
				uni.requestPayment({
					timeStamp: config.timestamp,
					nonceStr: config.nonceStr,
					package: config.package,
					signType: config.signType,
					paySign: config.paySign,
					success: (res) => {
						this.$util.Tips({
							title: '支付成功',
							icon: 'success'
						});
						this.type = 'success'
						// 餐饮预定
						storeMerchantInsertMerchantReserve({
							person_number: this.person_number,
							desk_id: this.desk_id,
							arrive_time: this.arrive_time,
							phone: this.phone,
							mer_id: this.id,
						}).then(res => {
							console.log(res)
							// uni.navigateTo({
							//   url: `/pages/2_development/store/book-result`
							// })
						})
					},
					fail: () => {
						return this.$util.Tips({
							title: '支付失败'
						});
					},
					complete: (res) => {
						if (res.errMsg == 'requestPayment:cancel') return this.$util.Tips({
							title: '取消支付'
						});
					}
				})
			},
			goHome() {
				uni.navigateBack({
					delta: 3
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #f8f8f8;
	}

	.result {
		width: 307px;
		height: 476px;
		display: block;
		margin: 35px auto;
		// background-color: #eee;
		padding-top: 20px;
		padding-left: 32px;
		padding-right: 32px;
		position: relative;
		.bg {
			position: absolute;
			z-index: -1;
			height: 100%;
			width: 100%;
			top: 0;
			left: 0;
		}
		.head {
			display: flex;
			align-items: center;
			justify-content: center;
			font-weight: bold;
			font-size: 18px;
			line-height: 1;
			color: #fff
		}

		.icon {
			width: 35px;
			height: 35px;
			margin-right: 18px;
		}

		.name {
			font-weight: bold;
			font-size: 18px;
			line-height: 1;
			text-align: center;
			color: #0b0b0b;
			margin-top: 40px;
		}

		.desc {
			font-size: 13px;
			line-height: 22px;
			color: #999;
			margin-top: 20px;
		}

		.info {
			height: 60px;
			border-radius: 4px;
			background: #f8f8f8;
			border: 1px solid #999;
			margin-top: 16px;
			padding-top: 12px;
			padding-right: 15px;
		}

		.info-item {
			display: flex;
			margin-bottom: 10px;

			.text1 {
				width: 57px;
				padding-left: 11px;
				font-size: 13px;
				line-height: 1;
				color: #333;
			}

			.text2 {
				flex: 1;
				font-size: 13px;
				line-height: 1;
				color: #999;
				width: 150px;
			}

			.text3 {
				font-size: 13px;
				line-height: 1;
				color: #333;
			}
		}

		.btn1 {
			height: 32px;
			line-height: 30px;
			text-align: center;
			border-radius: 16px;
			background: #0193ff;
			border: 1px solid #0193ff;
			color: #fff;
			font-size: 16px;
			margin-top: 95px;
		}

		.btn2 {
			height: 32px;
			line-height: 30px;
			text-align: center;
			border-radius: 16px;
			background: #fff;
			border: 1px solid #dcdcdc;
			color: #111111;
			font-size: 16px;
			margin-top: 19px;
		}

		.err-text {
			font-size: 16px;
			line-height: 1;
			text-align: center;
			color: #999;
			margin-top: 54px;
		}

		.btn3 {
			width: 162px;
			margin: 57px auto 0;
		}
	}
</style>
